package com.bsy.common.helper

import android.text.TextUtils
import android.widget.TextView
import com.google.android.material.tabs.TabLayout

/**
 * Created by Sincerity on 2024/5/22.
 * Copyright
 * 描述：
 */
fun TabLayout.Tab.setTabItemSingleLine() {
    try {
        val field = view.javaClass.getDeclaredField("defaultMaxLines")
        val fieldTextVew = view.javaClass.getDeclaredField("textView")
        field.isAccessible = true
        fieldTextVew.isAccessible = true
        val textView = fieldTextVew.get(view) as TextView
        textView.ellipsize = TextUtils.TruncateAt.MIDDLE
        field.setInt(view, 1)
    } catch (e: Exception) {
        e.printStackTrace()
    }
}